using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace SevenPieceGame
{
    public class UIShopButton : MonoBehaviour
    {
        private Button m_BtnShop;
        private Text m_TxtShopTitle;
        private Text m_TxtShopCM;
        private void Awake()
        {
            Create();
        }
    
        private void Create()
        {
            m_TxtShopTitle = this.transform.Find("Text2").GetComponent<Text>();
            m_TxtShopCM = this.transform.Find("Text1").GetComponent<Text>();
            
            m_BtnShop = this.transform.GetComponent<Button>();
            m_BtnShop.onClick.AddListener(OnClickShopBtn);
        }
        
        private void OnClickShopBtn()
        {
            MainManager.Instance.ShowUIShop();
        }
        
        public void SetShopBtnData()
        {
            ShopListItemData _data = UIShopManager.Instance.GetShowItemData();
            if (_data != null)
            {
                if (_data.m_ItemState == (int)UIShopManager.PaypalAndCashingItemType.phase_1)
                {
                    this.gameObject.SetActive(true);
                    m_TxtShopTitle.text = $"${_data.m_Index * 1000}";
                    m_TxtShopCM.text = $"{_data.m_CMCountProgress}/50";
                }
                else if (_data.m_ItemState == (int)UIShopManager.PaypalAndCashingItemType.phase_5)
                {
                    this.gameObject.SetActive(true);
                    m_TxtShopTitle.text = $"${_data.m_Index * 1000}";
                    m_TxtShopCM.text = $"{_data.m_Phase5CMCount}/50";
                }
            }
            else
            {
                this.gameObject.SetActive(false);
            }
        }
    }
}

